Repository navigation
Conversation
Resolve lexical paths and binding patterns without eagerly inferring their enclosing bodies. Filter field, method, and binding candidates during module reference searches. AI-assisted-by: OpenAI Codex
|
Is this PR text AI-written? Please read and follow the AI policy. |
|
Besides the PR text probably being AI-written,
Which is why I'm closing this. |
No, I wrote it but asked AI to improve its wording since I am not a native speaker.
I always excessively document my code. It make the life much easier when you refactor it. |
You don't need to write this unless you are a LLM. We have CI after all. And actually, I could hardly belive that sentence is written by human because no one would run tests like |
I think you are a bit paranoic about AI. I think it is wrong but the repo is yours and you are free to set your own rules. |
|
See #23746 for what I mean by "lazily" (module changes not included). |
Find All References starts with a search for matching names. When looking for a module named
config, rust-analyzer can also encounter unrelated locals, fields, and methods namedconfig. Classifying those candidates can trigger type inference for entire function bodies. That work can dominate the first reference search after indexing, when those bodies have yet to be inferred.This change skips candidates whose syntax rules out a module reference. It also uses lexical resolution for path qualifiers, confirmed local variables, and bare identifier patterns. Paths that need type information, such as type-dependent associated items, still use the inference-based resolver. The change is in rust-analyzer’s reference search and applies to any editor that uses it.
Zed benchmark
On rust-analyzer’s own repository, the first Find All References request for the
configmodule took a median of 769 ms before the patch and 80 ms after it, an 89.6% reduction. All ten completed requests returned the same 21 locations, with identical file URIs and ranges, including the declaration.Measured in Zed Preview 1.31.0 on an Apple M5 Max. The runs alternated between binaries and used a fresh server process for each request. The timer covers
textDocument/referencesfrom dispatch to response, after indexing and before the editor renders the results. One extra baseline attempt was interrupted by an early server restart. Its completed repeat is run 4.Reproduce in Zed
9c4c59a4c6e0andcce8b9bcc163withcargo +1.99.0 build --locked --release -p rust-analyzer --bin rust-analyzer. Save the binaries at separate paths.9c4c59a4c6e0for both variants. Select the binary withlsp.rust-analyzer.binary.pathin the project’s Zed settings. SetRUSTUP_TOOLCHAINto1.99.0for the server and setcheckOnSavetofalsein its initialization options. Zed Rust settingsconfigin the outerpub mod config;declaration at line 61, column 10. Run Find All References once from the command palette. Source locationRegression coverage
test_find_all_refs_decl_modulenow checks a module that shares its name with a local binding, a field, and a method. It verifies that the import and the qualified use inside a function are still reported. Coverage marks confirm that the two candidate rejection paths are exercised. All 1,347 IDE library tests passed withcargo +1.99.0 test --locked --release -p ide --lib.Codex assisted with profiling, the patch, the regression test, and the benchmark.